//
//
//
(function () {
	var params = arguments[0],
		addEvent,
		onScriptLoad,
		namespace;
	
	addEvent = (function () {
		if (window.addEventListener) {
			return function (el, ev, fn) {
			    el.addEventListener(ev, fn, false);
			};
		} else if (window.attachEvent) {
			return function (el, ev, fn) {
				el.attachEvent('on' + ev, fn);
			};
		} else {
			return function (el, ev, fn) {
				el['on' + ev] =  fn;
			};
		}
	}());
	
    // script element demands special treatment
    onScriptLoad = (function () {
    	// dumb script element just for features detection
    	var dumbscript = document.createElement("script");
        dumbscript.type = "text/javascript";
    	
        if (dumbscript.readyState) {  // old IEs
            return function (/*script element*/s, /*callback*/cb) {
            	s.onreadystatechange = function () {
                    if (s.readyState === "loaded" || s.readyState === "complete") {
                        s.onreadystatechange = null;
                        cb();
                    }
                };
        	};
        } else {  // modern browsers
        	return function (/*script element*/s, /*callback*/cb) {
        		s.addEventListener("load", cb, false);
        	};
        }
    }());

    namespace = window[params.namespace] = {
    	'addEvent': addEvent,
    	'onScriptLoad': onScriptLoad
    };
    
    (function () {
        var dojoScriptElem = document.createElement('script');
        dojoScriptElem.type = 'text/javascript';
        dojoScriptElem.src = params.dojo_url;
        dojoScriptElem['data-dojo-config'] = "async:1";
                    
        namespace.onDojoAMDReady = function (/*callback*/cb) {
            if (window.require) {
            	cb();
            } else {
            	onScriptLoad(dojoScriptElem, cb);
            }
        };
        document.getElementsByTagName('head')[0].appendChild(dojoScriptElem);
    }());
    
}({"namespace": "MYNAMESPACE",
	"dojo_url": "http://yandex.st/dojo/1.7.2/dojo/dojo.js"}));